var __TMPL_HTML,_item_wrap;
//暂时废弃表头加载 放入到页面中 此函数暂停使用
var callback_head = function(){
	var _head_html = '<thead><tr><th><input name="" type="checkbox"/></th><th>编号<i class="sort"><img src="'+parent.basePath+parent._image_suffix+'px.gif" /></i></th><th>用户名</th><th>身份证</th><th>婚姻状态</th>';
	_head_html = _head_html + '<th>性别</th><th>籍贯</th><th>手机号码</th><th>邮箱</th><th>注册时间</th><th>操作</th></tr></thead>';
	$('table.tablelist').prepend($(_head_html));
};
/**
 * 查询一般配置
 */
var common_param = {
		rows : 3,
		page : 1,
		'beanProxy[enable]' :0
};
/**
 * 带转换的列
 */
var change_select_data = {
		'clientMaritalStatus':{0:'未婚',1:'已婚'},
		'clientSex':{'0':'女','1':'男'}
};
//var _edit_user_ = function(id){
//	///
//};


//var change_select_data = {
	//	'clientMaritalStatus':{0:[{fuc:_edit_user_,name:'编辑'},_del_user],1:[_add_user_,_edit_user_]}
//};


/**
 * 加入改变样式函数
 */
var callback_change_css = function(_html,i){
	if(i%2 != 0 && _html){
		_html = _html.replace('<tr>','<tr class="odd">');
	}
	return _html;
};



/**
 * 配置分页栏目
 */
var callback_page = function(total,opt_init){
	$("div.pagination").pagination(total, opt_init);
	$("div.pagination").append($(parent._set_page_message(total,opt_init.current_page+1)));
};

var _edit_user_ = function(id){
	parent._do_goto_right(parent.basePath + 'jsp/user/user_edit.jsp?id='+id);
};

$(function(){
	//添加事件
	$('li._class_btn_add').click(function(){
		parent._do_goto_right(parent.basePath + 'jsp/user/user_edit.jsp');
	});
	//加载定义的数据网格格式
	__TMPL_HTML  = $("#tmpl_user_item").html();
	//加载数据显示的上级标签
	_item_wrap = $('table.tablelist').find('tbody');
	_item_wrap.empty();
	//分页查询的自定义参数
	var _param_call_data = {
			'callback_page':callback_page,
			'change_select_data':change_select_data,
			'callback_change_css':callback_change_css,
			'method':'POST'
	};
	//批量删除事件
	$('li._class_btn_del').click(function(){
		var ids = _get_all_select_value();
		if(ids.length>0){
			var conf = {'tip_title':'提示信息','tip_content':'删除不可恢复，确定删除？'};
			_set_dailog(conf,function(){
				_del_data(parent.basePath +'sys/Client/delete',{pks:ids},function(){
					parent._query_list(parent.basePath +'sys/Client/list', _item_wrap ,common_param,0,__TMPL_HTML,_param_call_data);
				});
			});
		}
		_set_open();
	});
	//新增记录以后自动加载标识
	if(is_auto_select && is_auto_select.length > 0){
		parent._query_list(parent.basePath +'sys/Client/list', _item_wrap ,common_param, 0,__TMPL_HTML,_param_call_data);
	}
	//查询事件
	$('input[name="query_btn"]').click(function(){
		 var array = $("#_form_search_default").serializeArray();
		 var queryParams = parent.array_to_obj(array, 'name', 'value');
		 queryParams['rows'] = common_param['rows'];
		 queryParams['page'] = common_param['page'];
		 parent._query_list(parent.basePath +'sys/Client/list', _item_wrap ,queryParams,0,__TMPL_HTML,_param_call_data);
	});
	
});

var _del_single_data = function(id){
	_set_dailog({'tip_title':'提示信息','tip_content':'删除不可恢复，确定删除？'},function(){
			_del_data(parent.basePath +'sys/Client/delete',{pks:id},function(){
				parent._query_list(parent.basePath +'sys/Client/list', _item_wrap ,common_param,0,__TMPL_HTML,_param_call_data);
			});
		});
	_set_open();
};
